/////////////////////////////////////////////////////////////////////////////
// Name:        ax_help_provider.h
// Purpose:     Special help text provider.
// Author:      Julian Smart
// Modified by:
// Created:     2009-04-16
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_HELP_PROVIDER_H_
#define _AX_HELP_PROVIDER_H_

#include "wx/cshelp.h"

#include "wx/html/htmlwin.h"
#include "wx/timer.h"

#if wxUSE_POPUPWIN
#include "wx/popupwin.h"
#endif

class AxSpeech;

/**
    @class AxHelpProvider

    A help provider class building on wxSimpleHelpProvider, but
    voicing the help as well as showing it.

    Use a line like this to set the help provider in your application
    initialisation code:

    @code
    wxHelpProvider::Set(new AxHelpProvider(& GetViewManager().GetSpeech()));
    @endcode

    See the wxWidgets manual for more on wxHelpProvider.

    This class uses its own tip window implementation, since the default
    wxTipWindow class is not very flexible and because it's based on a frame,
    causes unnecessarily focus setting and therefore repeated control description.
    In contrast, AxHtmlToolTip uses wxPopupWindow where possible. It can also support
    more interesting text.

    @category{ax}
 */

class AxHelpProvider : public wxSimpleHelpProvider 
{
public:

    AxHelpProvider(AxSpeech* speech = NULL);
    ~AxHelpProvider();

    void Init();

    wxString GetWindowOrAdapterHelp(const wxWindowBase *window);

    virtual wxString GetHelp(const wxWindowBase *window);

    virtual bool ShowHelp(wxWindowBase *window);

    AxSpeech* GetSpeech() const { return m_speech; }
    void SetSpeech(AxSpeech* speech) { m_speech = speech; }

    static void SetHelpWindow(wxWindow* helpWindow) { sm_helpWindow = helpWindow; }

    /// Clean up dialog
    static void CleanUp();

    static wxWindow* sm_helpWindow;
    static wxWindow* sm_invokedFrom;

    AxSpeech* m_speech;
};

#if wxUSE_POPUPWIN
class AxHtmlToolTip: public wxPopupWindow
#else
class AxHtmlToolTip: public wxFrame
#endif
{
    DECLARE_EVENT_TABLE()
    DECLARE_CLASS(AxHtmlToolTip)
public:
    AxHtmlToolTip(wxWindow* window);
    AxHtmlToolTip() { Init(); }
    ~AxHtmlToolTip();

    void Init();

    bool CreateWindow();

    virtual wxHtmlWindow* CreateHtmlWindow();

    void OnCloseWindow(wxCloseEvent& event);

    // Set the plain text or HTML
    void SetTip(const wxString& tip);

    // Use this to start showing the tip
    void StartShowing();

    // Move the tip to a suitable position relative to the object whose size
    // is defined by rect
    void MoveToGoodPosition(const wxRect& rect);

    // Set width
    void SetWidth(int width) { m_htmlWidth = width; }
    int GetWidth() const { return m_htmlWidth; }

    // Set margin between object and tip
    void SetMargin(int margin) { m_margin = margin; }
    int GetMargin() const { return m_margin; }

    // Set show duration in milliseconds
    void SetShowDuration(int duration) { m_showDuration = duration; }
    int GetShowDuration() const { return m_showDuration; }

    // Set auto-destroy
    void SetAutoDestroy(bool autoDestroy) { m_autoDestroy = autoDestroy; }
    bool GetAutoDestroy() const { return m_autoDestroy; }

    // Set/get calling window
    void SetCallingWindow(wxWindow* callingWindow) { m_callingWindow = callingWindow; }
    wxWindow* GetCallingWindow() const { return m_callingWindow; }

    // Set/get HTML window
    void SetHtmlWindow(wxHtmlWindow* win) { m_htmlWindow = win; }
    wxHtmlWindow* GetHtmlWindow() const { return m_htmlWindow; }

    void OnTimeout(wxTimerEvent& event);
    void OnChar(wxKeyEvent& event);

    wxHtmlWindow*   m_htmlWindow;
    wxWindow*       m_callingWindow;
    int             m_htmlWidth;
    int             m_margin;
    wxTimer         m_timer;
    int             m_showDuration;
    bool            m_autoDestroy; // destroy on timeout
};

#endif // _AX_HELP_PROVIDER_H_

